package com.stadium.service.impl;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.stadium.common.utils.SqlMapper;
import com.stadium.common.utils.UserUtils;
import com.stadium.dto.UserMessageDto;
import com.stadium.entity.UserMessage;
import com.stadium.mapper.UserMessageMP;
import com.stadium.service.UserMessageSV;
import com.stadium.vo.UserMessageVo;
import com.stadium.vo.searchVo.UserMessageSearchVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserMessageSVI implements UserMessageSV {
    @Autowired
    private UserMessageMP mapper;
    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<UserMessage> queryBySQL(String sql, Map<String, Object> map) {
        return sqlMapper.selectList(sql, map, UserMessage.class);
    }

    @Override
    public void save(UserMessageVo userMessageVo) {
        UserMessage userMessage = new UserMessage();
        BeanUtils.copyProperties(userMessageVo, userMessage);
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        userMessage.setCreateUser(UserUtils.getUserId());
        userMessage.setUpdateUser(UserUtils.getUserId());
        userMessage.setId(id);
        mapper.save(userMessage);
    }

    @Override
    public void update(UserMessageVo userMessageVo) {
        UserMessage userMessage = new UserMessage();
        BeanUtils.copyProperties(userMessageVo, userMessage);
        userMessage.setUpdateUser(UserUtils.getUserId());
        mapper.update(userMessage);
    }

    @Override
    public void saveBatch(List<UserMessage> list) {
        mapper.saveBatch(list);
    }

    @Override
    public void delete(String id) {
        mapper.delete(id);
    }

    @Override
    public void deleteBatch(String[] ids) {
        mapper.deleteBatch(ids);
    }

    @Override
    public List<UserMessageDto> query(UserMessageSearchVo searchVo) {
        return mapper.query(searchVo);
    }

    @Override
    public UserMessageDto get(String id) {
        return mapper.get(id);
    }

    @Override
    public int getCount(UserMessageSearchVo searchVo) {
        return mapper.getCount(searchVo);
    }

}
